import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/common/index.dart';
import 'package:provider/provider.dart';
import '../provide/details_info_provider.dart';
import '../provide/details_info_provider.dart';
import './details_page/details_top_area.dart';
import './details_page/details_explain.dart';
import './details_page/details_tabBar.dart';
import './details_page/details_web.dart';
import './details_page/details_bottom.dart';

class DetailsPage extends StatelessWidget {
  final String goodsId;

  DetailsPage(this.goodsId);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading: IconButton(
            icon: Icon(Icons.arrow_back_ios),
            onPressed: () {
//              print('返回上一页');
              Navigator.pop(context);
            },
          ),
          centerTitle: true,
          title: Text('商品详细页'),
        ),
        body: FutureBuilder(
            future: _getBackInfo(context),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                return Container(
                  width: ScreenUtil.screenWidth,
                  child: Column(
                    children: <Widget>[
                      Expanded(
                        child: ListView(
                          children: <Widget>[
                            DetailsTopArea(),
                            DetailsExplain(),
                            SizedBox(height: 10.h),
                            DetailsTabBar(),
                            SizedBox(height: 10.h),
                            DetailsWeb(),
                          ],
                        ),
                      ),
                      SizedBox(height: 30.h),
                      DetailsBottom()
                    ],
                  ),
                );
              } else {
                return buildLoadingIndicator();
              }
            }));
  }

  Future _getBackInfo(BuildContext context) async {
    await context.watch<DetailsInfoProvider>().getGoodsInfo(goodsId);
    return '完成加载';
  }
}
